package ai.people.netmon.framework.domain.archives.vo;

import ai.people.netmon.framework.businessenum.WorkOrderRoleEnum;
import ai.people.netmon.framework.domain.archives.entity.WorkOrderReplay;
import ai.people.netmon.framework.domain.archives.entity.WorkOrderState;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * 工单详情
 * @author zhenglin
 * @date 2022/5/31
 */
@Data
public class WorkOrderDetailVO {
    /**
     * 描述
     */
    private String describe;

    /**
     * 联系方式
     */
    private String contact;

    /**
     * 附件
     */
    private String attachments;

    /**
     * 消息列表，按时间排序,包括：系统消息、用户回复、管理员回复
     */
    List<Msg> msgList;

    @Data
    @NoArgsConstructor
    public static class Msg{
        /**
         * 类型 1-系统消息 2-用户回复 3-管理员回复
         */
        private Integer type;
        /**
         * 时间
         */
        @JSONField(format = "yyyy-MM-dd HH:mm:ss")
        private Date time;
        /**
         * 信息
         */
        private String msg;

        /**
         * 回复附件
         */
        private String msgAttachments;

        /**
         * 是否是管理员
         */
        private Boolean isAdmin;

        public Msg(WorkOrderReplay workOrderReplay, Integer code) {
            this.type = code;
            this.time = workOrderReplay.getReplayTime();
            this.msg = workOrderReplay.getReplayMsg();
            this.msgAttachments = workOrderReplay.getReplayAttachments();
            this.isAdmin = Objects.equals(workOrderReplay.getReplayRoleType(), WorkOrderRoleEnum.ADMIN.code);
        }

        public Msg(WorkOrderState workOrderState, Integer code) {
            this.type = code;
            this.time = workOrderState.getUpdateTime();
            //如果是系统消息，msg里面存的是状态
            this.msg = String.valueOf(workOrderState.getOrderType());
            this.isAdmin = Objects.equals(workOrderState.getRoleType(), WorkOrderRoleEnum.ADMIN.code);
        }
    }
}
